using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DTO;
using DAO;
namespace BUS
{
    public enum SachBUSResult
    {
        OK,DAOERROR
    }
    public class Sach
    {
        public static SachBUSResult SelectAll(List<DTO.Sach> danhSach)
        {
            string sql = "select * from Sach";
            DAO.Interface s = new DAO.Sach();
            DataTable dt = s.Select(sql);
            if(dt!= null)
            {
                for(int i=0;i<dt.Rows.Count;i++)
                {
                    DTO.Sach sa = new DTO.Sach();
                    sa.MaSach = dt.Rows[i].ItemArray[0].ToString();
                    while (sa.MaSach.IndexOf(" ") >= 0)
                        sa.MaSach = sa.MaSach.Replace(" " , "");
                    sa.MaTheLoai = dt.Rows[i].ItemArray[1].ToString();
                    sa.TenSach = dt.Rows[i].ItemArray[2].ToString();
                    sa.TacGia = dt.Rows[i].ItemArray[3].ToString();
                    sa.NamXuatBan =int.Parse(dt.Rows[i].ItemArray[4].ToString());
                    sa.NhaXuatBan = dt.Rows[i].ItemArray[5].ToString();
                    sa.NgayNhap = Convert.ToDateTime(dt.Rows[i].ItemArray[6]); ;
                    sa.GiaSach = int.Parse(dt.Rows[i].ItemArray[7].ToString());
                    danhSach.Add(sa);
                }
                return SachBUSResult.OK;
            }
            return SachBUSResult.DAOERROR;
        }
    }
}
